<#include "/common/head.html"/>
<div class="easyui-panel updatePage" data-options="fit:true,border:false">
	<form class="easyui-form" id="ff" method="post" data-options="novalidate:true" enctype="multipart/form-data">
		<table class="table1">
			<tr>
				<th><span id="name_label">选择文件：</span></th>
				<input id="templateId" name="templateId" type="hidden" value="${id}" />
				<td>
					<div class="wrap_input">
						<input id="ec_file" name="fileUpload" style="width: 300px">
					</div>
				</td>
			</tr>
		</table>
	</form>
</div>
<script>
	top.window.subPage.save = save;
	$('#ec_file').filebox({
		buttonText : '选择文件',
		buttonAlign : 'left'
	});

	function save() {
		var files = $("#ec_file").next().find('input[type=file]')[0].files;
		var file = files[0];
		if (file) {
			$("#ff").form("submit", {
				url : "upload",
				onSubmit : function(param) {
					var fileName = file.name;
					var flag = false;
					var arr = [ "pdf", "docx", "doc" ];
					var index = fileName.lastIndexOf(".");
					var ext = fileName.substr(index + 1);
					for (var i = 0; i < arr.length; i++) {
						if (ext == arr[i]) {
							flag = true;
							break;
						}
					}
					if (flag) {
						param.templateId = $("#templateId").val();
						param.fileUpload = file;
						console.log(param)
					} else {
						showMsg("请选择PDF或WORD文件上传！");
						return false;
					}
				},
				success : function(data) {
					top.window.closeWindow();
					top.window.subPage.loadCurrDatagrid();
					showMsg("上传成功！");
				}
			})
		} else {
			showMsg("请选择文件！");
		}
	}
</script>
<#include "/common/foot.html"/>
